import { request } from './request'

export const apiSendEmailVerificationCode = (data) => {
  var raw = JSON.stringify({
    "email": data
  });
  return request("/base/sendEmailVerificationCode", 'post', raw)
}

const userRouter = "/user"
// 注册
export const apiRegisterUserByEmail = (data) => {
  var raw = JSON.stringify({
    "no": data.no,
    "email": data.email,
    "password": data.password,
    "username": data.username,
    "verification_code": data.code
  });
  return request(userRouter, 'post', raw)
}

// 登录
export const apiLoginByEmail = (data) => {
  var raw = JSON.stringify({
    "email": data.email,
    "password": data.password
  });
  return request(userRouter + '/login', 'post', raw)
}

// 忘记密码
export const apiForgotPassword = (data) => {
  var raw = JSON.stringify({
    "email": data.email,
    "new_password": data.password,
    "verification_code": data.code
  });
  return request(userRouter + "/forgotPassword", 'post', raw)
}

// 重置密码
export const apiResetPassword = (data) => {
  var raw = JSON.stringify({
    "password": data.password,
    "new_password": data.newPassword,
  });
  return request(userRouter + "/resetPassword", 'put', raw)
}

// 修改用户信息，目前仅限于修改 username
export const apiChangeUserInfo = (data) => {
  var raw = JSON.stringify({
    "username": data.username
  });
  return request(userRouter + "/changeInfo", 'put', raw)
}

// 获取用户信息
export const apiGetUserInfo = () => {
  return request(userRouter)
}

// 用户退出登录
export const apiDelUser = () => {
  return request(userRouter,'delete')
}